local kl__zhiqiang = fk.CreateSkill {
  name = "kl__zhiqiang",
}

kl__zhiqiang:addEffect("viewas", {
  anim_type = "offensive",
  pattern = "slash",
  prompt = "#kl__zhiqiang",
  interaction = function(self, player)
    local all_names = {}
    for _, id in ipairs(Fk:getAllCardIds()) do
      local card = Fk:getCardById(id, true)
      if card.trueName == "slash" and not card.is_derived then
        table.insertIfNeed(all_names, card.name)
      end
    end
    local names = player:getViewAsCardNames(kl__zhiqiang.name, all_names)
    if #names == 0 then return end
    return UI.CardNameBox { choices = names, all_choices = all_names }
  end,
  handly_pile = true,
  card_filter = function(self, player, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).type == Card.TypeEquip
  end,
  view_as = function(self, player, cards)
    if #cards ~= 1 or not self.interaction.data then return end
    local card = Fk:cloneCard(self.interaction.data)
    card:addSubcard(cards[1])
    card.skillName = kl__zhiqiang.name
    return card
  end,
  before_use = function(self, player, use)
    use.extraUse = true
    local room = player.room
    local tos = use.tos
    for _, p in ipairs(tos) do
      local choices = {}
      if #p:getCardIds("he") >= 2 then
        table.insert(choices, "kl__zhiqiang-1:::".. use.card:toLogString())
      end
      table.insert(choices, "kl__zhiqiang-2:"..player.id.."::"..use.card:toLogString())
      local choice = room:askToChoice(p, {
        choices = choices,
        skill_name = kl__zhiqiang.name,
        cancelable = false,
      })
      if choice:startsWith("kl__zhiqiang-1") then
        room:loseHp(p, 1, kl__zhiqiang.name)
        room:askToDiscard(p,{
          min_num = 2,
          max_num = 2,
          include_equip = false,
          pattern = ".|.|.|hand",
          skill_name = kl__zhiqiang.name,
          cancelable = false,
        })
        use.nullifiedTargets = table.simpleClone(player.room.players)
      elseif choice:startsWith("kl__zhiqiang-2") then
        use.additionalDamage = (use.additionalDamage or 0) + player:getLostHp()
      end
    end
  end,
  enabled_at_play = function(self, player)
    return player:usedSkillTimes(kl__zhiqiang.name) == 0
  end,
  enabled_at_response = function(self, player, response)
    return not response and player:usedSkillTimes(kl__zhiqiang.name) == 0
  end,
})

kl__zhiqiang:addEffect("targetmod", {
  bypass_times = function (self, player, skill, scope, card, to)
    return card and table.contains(card.skillNames, kl__zhiqiang.name)
  end,
})

kl__zhiqiang:addEffect(fk.TargetSpecified, {
  can_refresh = function(self, event, target, player, data)
    return table.contains(data.card.skillNames, kl__zhiqiang.name) and not data.to.dead and data.card.trueName == "slash"
  end,
  on_refresh = function(self, event, target, player, data)
    data.to:addQinggangTag(data)
  end,
})



return kl__zhiqiang
